using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;

namespace TrainingManagement.api.Models.Data.CRUD.Employee
{
    public class EmployeeUpdateDataSource : NonQuerySource<BusinessObjects.Employee>
    {
        public override bool Execute(BusinessObjects.Employee request)
        {
            const string employeeUpdate = "dbo.training_api_EmployeeUpdate";
            var parameters = new SqlParameter[7];
            parameters[0] = new SqlParameter("@EmployeeID", SqlDbType.Int){ Value = request.EmployeeId};
            parameters[1] = new SqlParameter("@FirstName", SqlDbType.NVarChar){Value = request.FirstName};
            parameters[2] = new SqlParameter("@LastName", SqlDbType.NVarChar){Value = request.LastName};
            parameters[3] = new SqlParameter("@Email", SqlDbType.NVarChar) { Value = request.Email };
            parameters[4] = new SqlParameter("@SmsNumber", SqlDbType.NVarChar) { Value = request.SmsNumber };
            parameters[5] = new SqlParameter("@DepartmentTreeId", SqlDbType.NVarChar) { Value = request.DepartmentTreeId };
            parameters[6] = new SqlParameter("@IsActive", SqlDbType.Bit) { Value = request.IsActive };

            return SqlHelper.ExecuteNonQuery(
                ConnectionStrings.TrainingDb,
                CommandType.StoredProcedure,
                employeeUpdate,
                parameters) != 0;
        }
    }
}